package kaufman.id.projects;

import java.util.Arrays;
import java.util.Random;

public class Assassin_pairing {

	static Random random = new Random();

	/**
	 * 
	 * @param players
	 * @param targets
	 */
	public static void repeatingNameCheck(String[] players) {
		// checks for repeating names and terminates if so while(true){
		for (int i = 0; i <= players.length - 1; i++) {
			for (int y = 0; y <= players.length - 1; y++) {
				if (players[i].equals(players[y]) && i != y) {
					System.exit(0);
				}
			}
		}
	}

	/**
	 * 
	 * @param targets
	 * @param players
	 */
	/*
	 * public static void swap(String[] targets, String[] players) {//
	 * psuedorandomly // swaps // targets while (true) { int Index1 =
	 * random.nextInt(players.length - 1);
	 * 
	 * int Index2 = random.nextInt(targets.length - 1); String tar1 =
	 * targets[Index1]; String tar2 = targets[Index2]; String play1 =
	 * players[Index1]; String play2 = players[Index2]; if (tar1 != play2 &&
	 * tar2 != play1) { // used toe check values if swapped, no clashes
	 * targets[Index1] = tar2; targets[Index2] = tar1; break; } }
	 * 
	 * }
	 */
	public static String[] randomizeOrder(String[] players) {
		boolean[] chosen = new boolean[players.length];
		String[] newOrder = new String[players.length];
		int counter = 0;
		while (counter < players.length)
			;
		int rand = random.nextInt(players.length - 1);
		if (!chosen[rand]) {
			newOrder[counter] = players[rand];
			counter++;
			chosen[rand] = true;
		}

		return newOrder;
		

	}

	/**
	 * 
	 * @param targets
	 */
	public static void rotateRight(String[] targets) {
		// rotates targets to the right one place
		String pre = targets[targets.length - 1];
		String current;

		for (int r = 0; r < targets.length; r++) {
			current = targets[r];// =DR
			targets[r] = pre;
			pre = current;
		}
	}

	//
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		String[] players = { "David", "Nate", "Matt", "Jason", "Kieran", "Wil",
				"Dan" };
		repeatingNameCheck(players);
		String[] targets = Arrays.copyOf(players, players.length);
		repeatingNameCheck(players);
		// loops through players
		rotateRight(targets);
		/*
		 * for (int i = 0; i < 43; i++) {// 42 possible permutations of 7nPr2*/
		  String[] newOrder = randomizeOrder(players); //}
		 
		for (int i = 0; i <= players.length - 1; i++) {

			System.out.println(newOrder[i]);

		}
	}
}
